home *** CD-ROM | disk | FTP | other *** search
- function checkCollision(mc2, mc1, tolerance, scope)
- {
- var _loc1_ = classes.CollisionDetection.checkForCollision(mc1,mc2,255);
- return _loc1_;
- }
- function adjust(v, threshold, maximum)
- {
- vx = 0;
- if(v <= threshold)
- {
- vx = v / threshold * 1;
- }
- else
- {
- vx = 1;
- }
- return vx;
- }
- function move()
- {
- this._rotation = angle * 180 / 3.141593;
- UD = Key.isDown(38) - Key.isDown(40);
- if(!hit)
- {
- LR = Key.isDown(39) - Key.isDown(37);
- }
- HAND = Key.isDown(32);
- if(LR && !hit)
- {
- angle += LR * UD * steer * adjust(Math.abs(speed),steer_threshold,MAXSpd);
- }
- else
- {
- turnskidding = false;
- }
- if(!UD & !hit)
- {
- speed *= drift;
- }
- else if(UD & !HAND & !hit)
- {
- speed = Math.min(Math.max(speed + UD * accel,MINspd),MAXspd);
- }
- if(Math.abs(speed) < accel / 2)
- {
- speed = 0;
- }
- if(HAND)
- {
- speed *= handbrake;
- if(speed > MAXskiddisplay)
- {
- steer = steer_handbrake;
- }
- traction = handbrake_traction / surface;
- }
- else
- {
- skidding = false;
- traction = Math.max(traction_max,Math.abs((speed - MAXturnSpd) / surface));
- steer = steer_normal;
- }
- if(speed <= 0)
- {
- traction = 1;
- }
- if(Key.isDown(32) && isPlayer && spaceUp)
- {
- _parent.valet_mc._x = this._x + 80 * Math.cos((this._rotation - 70) * 3.141592653589793 / 180);
- _parent.valet_mc._y = this._y + 80 * Math.sin((this._rotation - 70) * 3.141592653589793 / 180);
- var _loc4_ = valetCheckB();
- if(_loc4_)
- {
- _root.userCar = "";
- spaceUp = false;
- isPlayer = false;
- _parent.valet_mc.hit = false;
- _parent.valet_mc._visible = true;
- }
- }
- if(!hit)
- {
- this._x += vector[0] += (Math.cos(angle) * speed - vector[0]) / traction;
- this._y += vector[1] += (Math.sin(angle) * speed - vector[1]) / traction;
- }
- }
- function hitCheck()
- {
- if(this.hitTest(_parent[_root.userCar].target_mc) && this._name != _root.userCar)
- {
- if(checkCollision(this,_parent[_root.userCar]) != undefined || checkCollision(this,_parent[_root.userCar]) != null)
- {
- _root.crash_snd.start();
- _parent[_root.userCar].hit = true;
- _parent[_root.userCar].health -= 3;
- allHit();
- this._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
- this._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
- _parent[_root.userCar].speed = (- _parent[_root.userCar].speed) * 1.5;
- _parent[_root.userCar].vector[0] = - _parent[_root.userCar].vector[0];
- _parent[_root.userCar].vector[1] = - _parent[_root.userCar].vector[1];
- _parent[_root.userCar]._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
- _parent[_root.userCar]._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
- _parent[_root.userCar].hit = false;
- if(this.isMovable)
- {
- this.health -= 10;
- }
- else
- {
- this.health -= (15 - this._currentframe) * 5;
- }
- if(this._currentframe == 13)
- {
- _root.cop_mc.gotoAndStop(2);
- var _loc4_ = new Sound();
- var _loc6_ = "snd" + _currentframe;
- _loc4_.attachSound(_loc6_);
- _loc4_.start();
- }
- if(this._currentframe > 13)
- {
- var _loc5_ = _parent.attachMovie("clip" + _currentframe,"man" + _currentframe,_parent.getNextHighestDepth());
- _loc4_ = new Sound();
- _loc6_ = "snd" + _currentframe;
- _loc4_.attachSound(_loc6_);
- _loc4_.start();
- _loc5_._x = this._x;
- _loc5_._y = this._y;
- this.health = 0;
- }
- }
- }
- }
- function valetCheck()
- {
- if(this.hitTest(_parent.valet_mc.hit_mc))
- {
- if(checkCollision(this,_parent.valet_mc) != undefined || checkCollision(this,_parent.valet_mc) != null)
- {
- _parent.valet_mc.hit = true;
- _parent.valet_mc.hitCar = this._name;
- if(Key.isDown(32) && !isPlayer && spaceUp && _root.userCar == "")
- {
- valetIn();
- }
- }
- }
- }
- function valetCheckB()
- {
- i = 0;
- while(i <= _root.carArray.length)
- {
- if(_parent.valet_mc.hit_mc.hitTest(_root.carArray[i]) && _root.userCar != _root.carArray[i]._name)
- {
- return false;
- }
- i++;
- }
- if(_parent.valet_mc.hit_mc.hitTest(_parent.car1_mc) && _root.userCar != "car1_mc")
- {
- return false;
- }
- if(_parent.valet_mc.hit_mc.hitTest(_parent.car2_mc) && _root.userCar != "car2_mc")
- {
- return false;
- }
- if(_parent.valet_mc.hit_mc.hitTest(_parent.car3_mc) && _root.userCar != "car3_mc")
- {
- return false;
- }
- return true;
- }
- function allHit()
- {
- i = 0;
- while(i <= _root.carArray.length)
- {
- if(this.hitTest(_root.carArray[i]) && _root.userCar != _root.carArray[i]._name)
- {
- if(checkCollision(this,_root.carArray[i]) != undefined || checkCollision(this,_root.carArray[i]) != null)
- {
- trace("hit");
- _root.carArray[i]._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
- _root.carArray[i]._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
- }
- }
- i++;
- }
- if(this.hitTest(_parent.car1_mc) && this._name != "car1_mc" && _root.userCar != "car1_mc")
- {
- if(checkCollision(this,_parent.car1_mc) != undefined || checkCollision(this,_parent.car1_mc) != null)
- {
- trace("hit");
- _parent.car1_mc._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
- _parent.car1_mc._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
- }
- }
- if(this.hitTest(_parent.car2_mc) && this._name != "car2_mc" && _root.userCar != "car2_mc")
- {
- if(checkCollision(this,_parent.car2_mc) != undefined || checkCollision(this,_parent.car2_mc) != null)
- {
- trace("hit");
- _parent.car2_mc._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
- _parent.car2_mc._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
- }
- }
- if(this.hitTest(_parent.car3_mc) && this._name != "car3_mc" && _root.userCar != "car3_mc")
- {
- if(checkCollision(this,_parent.car3_mc) != undefined || checkCollision(this,_parent.car3_mc) != null)
- {
- trace("hit");
- _parent.car3_mc._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
- _parent.car3_mc._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
- }
- }
- }
- function valetIn()
- {
- _root.userCar = this._name;
- spaceUp = false;
- if(isMovable)
- {
- isPlayer = true;
- _parent.valet_mc._visible = false;
- }
- }
- function valetCheck2()
- {
- _parent.valet_mc.block = false;
- if(this.hitTest(_parent.valet_mc.hit_mc))
- {
- if(checkCollision(this,_parent.valet_mc) != undefined || checkCollision(this,_parent.valet_mc) != null)
- {
- _parent.valet_mc.block = true;
- }
- }
- }
- function checkHealth()
- {
- if(health > 0)
- {
- this.target_mc.gotoAndStop(5 - Math.ceil(health / 25));
- }
- else
- {
- this.gotoAndStop(_totalframes);
- var _loc4_ = _parent.blast_mc.attachMovie("blast","blast" + _parent.blast_mc.getNextHighestDepth(),_parent.blast_mc.getNextHighestDepth());
- _loc4_._x = this._x;
- _loc4_._y = this._y;
- _loc4_._xscale = _loc4_._yscale = 60;
- _loc4_.parent = this._name;
- if(!(this._name == "car1_mc" || this._name == "car2_mc" || this._name == "car3_mc"))
- {
- if(this.isMovable && this._name == _root.userCar)
- {
- _parent.valet_mc._x = this._x;
- _parent.valet_mc._y = this._y;
- _root.userCar = "";
- spaceUp = false;
- isPlayer = false;
- _parent.valet_mc.hit = false;
- _parent.valet_mc._visible = true;
- }
- _root.score += 500;
- }
- }
- }
- gotoAndStop(myFrame);
- var scope = _parent;
- var tolerance = 120;
- if(this._name != "car1_mc" && this._name != "car2_mc" && this._name != "car3_mc")
- {
- this._name = "Ocar" + _root.carCount++;
- _root.carArray.push(this);
- }
- var accel = 0.3;
- var steer = 0.04;
- var steer_normal = 0.08;
- var steer_handbrake = 0.099;
- var steer_threshold = 4;
- var MINspd = -5;
- var MAXspd = 15;
- var MAXskiddisplay = 2;
- var MAXturnSpd = 10;
- var MaxTurnSkid = 18;
- var deccel = 0.92;
- var handbrake = 0.33;
- var handbrake_traction = 20;
- var drift = 0.48;
- if(_root.level > 5)
- {
- drift = 0.88;
- if(_root.level > 10)
- {
- drift = 0.38;
- if(_root.level > 15)
- {
- drift = 0.18;
- }
- }
- }
- var speed = 0;
- var surface = 1;
- var traction = 2;
- var traction_max = 1;
- var vector = [0,0];
- var bounceBack = 0.4;
- var angle = this._rotation / 180 * 3.141593;
- var skidding = false;
- var turnskidding = false;
- var hit = false;
- var prevX;
- var prevY;
- var myCar;
- var health = 100;
- var isPlayer = false;
- var r = this._width / 2 + _parent.valet_mc._width / 2;
- var diag = Math.sqrt(this._width * this._width + this._height * this._height) / 2;
- var isPlayer = false;
- var spaceUp = true;
- var prevName = "";
- onEnterFrame = function()
- {
- if(this._currentframe != _totalframes)
- {
- checkHealth();
- if(isPlayer)
- {
- if(!hit)
- {
- move();
- }
- }
- else
- {
- valetCheck();
- hitCheck();
- }
- if(!Key.isDown(32))
- {
- spaceUp = true;
- }
- }
- };
-